package learn.up.java.thread;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ThreadLocalDemo2 {

	private static ThreadLocal<Connection> local = new ThreadLocal<Connection>() {

		@Override
		protected Connection initialValue() {
			Connection connection = null;
			try {
				connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "username",  
				            "password");
			} catch (SQLException e) {
				e.printStackTrace();
			}
			return connection;
		}
		
	};
	
	public static Connection getConnection() {
		return local.get();
	}
	
	public static void setConnection(Connection connection) {
		local.set(connection);
	}
	
}
